package cn.tedu.restaurant.service.impl;

import cn.tedu.restaurant.entity.Comment;
import cn.tedu.restaurant.mapper.CommentMapper;
import cn.tedu.restaurant.service.CommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author JachinLin
 * @since 2020-10-07
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper, Comment> implements CommentService {

    @Autowired
    @Resource
    private CommentMapper commentMapper;

    @Override public void insertComment(String nickname, String content, Integer id, String username) {
        Comment comment = new Comment();
        comment.setContent(content);
        comment.setCreatedTime(new Date());
        comment.setNickname(nickname);
        comment.setId(id);
        comment.setCreatedUser(username);
        commentMapper.insert(comment);
    }

    @Override public List<Comment> listComment(Integer id) {
        return commentMapper.selectByDId(id);
    }
}
